package com.xdw.vuebackdemo.service.impl;

import com.xdw.vuebackdemo.constant.Constant;
import com.xdw.vuebackdemo.mapper.UserMapper;
import com.xdw.vuebackdemo.model.User;
import com.xdw.vuebackdemo.service.UserService;
import com.xdw.vuebackdemo.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @author xiadewang
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RedisUtil redisUtil;

    @Override
    public User login(String username, String password) {
        return userMapper.findByUsernameAndPassword(username,password);
    }

    @Override
    public boolean checkToken(long userid, String token) {

        return false;
    }

    @Override
    public boolean checkToken(long userid, String token, String clientType) {
        if(clientType==null || clientType.isEmpty()){
            clientType = Constant.CLIENT_TYPE_WEB;
        }
        Object o = redisUtil.hget(Constant.TOKEN_KEY_PREFIX +userid,clientType);
        if(o!=null){
            return true;
        }
        return false;
    }

    @Override
    public User getUserByUserid(long userid) {
        return null;
    }

}
